const Koa = require('koa')
const Router = require('koa-router')
const Boom = require('boom')
const bodyParser = require('koa-bodyparser')
const serve = require('koa-static')
const path = require('path')
const config = require('../config')
const app = new Koa()
const router = new Router()

app.use(router.routes())

/* eslint-disable */
app.use(router.allowedMethods({
  throw: true,
  notImplemented: () => new Boom.notImplemented(),
  methodNotAllowed: () => new Boom.methodNotAllowed()
}))

// 使用bodyparser 解析get,post的参数
app.use(bodyParser())

const main = serve(path.join(__dirname));
app.use(main);

// log error
app.on('error', (err, ctx) => {
  console.log('server error', err, ctx)
})

app.listen(config.dev.mockServerPort)
